﻿Imports Framework.Data

Public Class MediaInfo
    Public Shared Function GetBySharedItemId(ByVal sharedItemId As Integer) As Entities.MediaInfo
        Return DataStore.MediaInfo.GetBySharedItemId(sharedItemId)
    End Function
    Public Shared Sub DeleteBySharedItemId(ByVal sharedItemId As Integer, ByVal transactionScope As TransactionScope)
        DataStore.MediaInfo.DeleteBySharedItemId(sharedItemId, transactionScope)
    End Sub
    Public Shared Sub Save(ByVal mediaInfo As Entities.MediaInfo)
        DataStore.MediaInfo.Save(mediaInfo)
    End Sub
    Public Shared Sub Save(ByVal mediaInfo As Entities.MediaInfo, ByVal transactionScope As Framework.Data.TransactionScope)
        DataStore.MediaInfo.Save(mediaInfo, transactionScope)
    End Sub
    Public Shared Function GetAllByShareIdAndWithGenres(ByVal shareId As Integer, ByVal withGenres() As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndWithGenres(shareId, withGenres)
    End Function
    Public Shared Function GetAllByShareIdAndInGenre(ByVal shareId As Integer, ByVal withGenres As Generic.List(Of String)) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndInGenre(shareId, withGenres)
    End Function
    Public Shared Function GetAllByFeatureIds(ByVal featureIds As Generic.List(Of String)) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByFeatureIds(featureIds)
    End Function

    Public Shared Function GetAllSubGenresByShareId(ByVal shareId As Integer, ByVal genrePrefix As Generic.List(Of String)) As Generic.List(Of String)
        Dim aGenreCombos As Generic.List(Of String)
        aGenreCombos = DataStore.MediaInfo.GetAllGenreCombinationsByShareId(shareId)
        Dim strGenrePrefix As String = Framework.Serialization.ToDBSeparatorString(genrePrefix, ";"c)
        Dim aKeep As New Generic.SortedList(Of String, String)
        For Each strCombo As String In aGenreCombos
            Dim strSubGenre As String
            If strGenrePrefix = ";;" Then
                Dim aRest() As String = strCombo.Substring(1).Split(";"c)
                strSubGenre = aRest(0)
            ElseIf strCombo.ToLower.StartsWith(strGenrePrefix.ToLower) Then
                Dim strRest As String = strCombo.Substring(strGenrePrefix.Length)
                If strRest.Length = 0 Then
                    strSubGenre = Nothing
                Else
                    Dim aRest() As String = strRest.Split(";"c)
                    strSubGenre = aRest(0)
                End If
            Else
                strSubGenre = Nothing
            End If
            If strSubGenre IsNot Nothing Then
                If Not aKeep.ContainsKey(strSubGenre.ToLower) Then
                    aKeep.Add(strSubGenre.ToLower, strSubGenre)
                End If
            End If
        Next
        Return aKeep.Values.ToList
    End Function



    Public Shared Function GetAllGenresByShareId(ByVal shareId As Integer, ByVal withGenres() As String) As Generic.List(Of String)
        Dim aKeep As New Generic.SortedList(Of String, String)
        Dim aGenreCombos As Generic.List(Of String)
        aGenreCombos = DataStore.MediaInfo.GetAllGenreCombinationsByShareId(shareId)
        If withGenres Is Nothing Then withGenres = New String() {}
        For Each strCombo As String In aGenreCombos
            Dim aInDb As Generic.List(Of String) = Framework.Serialization.FromDBSeparatorString(strCombo)
            Dim blnOk As Boolean = True
            For Each strWith As String In withGenres
                Dim blnExists As Boolean = False
                For Each strExisting As String In aInDb
                    If strWith.ToLower.Trim = strExisting.ToLower.Trim Then
                        blnExists = True
                        Exit For
                    End If
                Next
                If Not blnExists Then
                    blnOk = False
                    Exit For
                End If
            Next
            If blnOk Then
                For Each strInDb As String In aInDb
                    Dim blnKeep As Boolean = True
                    For Each strWith As String In withGenres
                        If strInDb.ToLower.Trim = strWith.ToLower.Trim Then
                            blnKeep = False
                            Exit For
                        End If
                    Next
                    If blnKeep Then
                        If Not aKeep.ContainsKey(strInDb.ToLower.Trim) Then
                            aKeep.Add(strInDb.ToLower.Trim, strInDb.Trim)
                        End If
                    End If
                Next
            End If
        Next
        Return aKeep.Values.ToList
    End Function

    Public Shared Function GetAllCertificationCountriesByShareId(ByVal shareId As Integer) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetAllCertificationCountriesByShareId(shareId)
    End Function
    Public Shared Function GetCertificationsByShareIdAndCountry(ByVal shareId As Integer, ByVal country As String) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetCertificationsLevelsByShareIdAndCountry(shareId, country)
    End Function
    Public Shared Function GetAllByShareIdAndCertification(ByVal shareId As Integer, ByVal country As String, ByVal level As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndCertification(shareId, country, level)
    End Function

    Public Shared Function GetAllActorsByShareId(ByVal shareId As Integer) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetAllActorsByShareId(shareId)
    End Function
    Public Shared Function GetAllByShareIdAndActor(ByVal shareId As Integer, ByVal name As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndActor(shareId, name)
    End Function

    Public Shared Function GetAllDirectorsByShareId(ByVal shareId As Integer) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetAllDirectorsByShareId(shareId)
    End Function
    Public Shared Function GetAllByShareIdAndDirector(ByVal shareId As Integer, ByVal name As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndDirector(shareId, name)
    End Function

    Public Shared Function GetAllWritersByShareId(ByVal shareId As Integer) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetAllWritersByShareId(shareId)
    End Function
    Public Shared Function GetAllByShareIdAndWriter(ByVal shareId As Integer, ByVal name As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndWriter(shareId, name)
    End Function

    Public Shared Function GetAllMoviePictureSizesByShareId(ByVal shareId As Integer) As Generic.List(Of Entities.Size)
        Return DataStore.MediaInfo.GetAllMoviePictureSizesByShareId(shareId)
    End Function
    Public Shared Function GetAllByShareIdAndSize(ByVal shareId As Integer, ByVal minWidth As Short, ByVal maxWidth As Short) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndSize(shareId, minWidth, maxWidth)
    End Function

    Public Shared Function GetAllAudioLanguagesByShareId(ByVal shareId As Integer) As Generic.List(Of String)
        Return DataStore.MediaInfo.GetAllAudioLanguagesByShareId(shareId)
    End Function
    Public Shared Function GetAllByShareIdAndAudioLanguage(ByVal shareId As Integer, ByVal language As String) As Generic.List(Of Entities.MediaInfo)
        Return DataStore.MediaInfo.GetAllByShareIdAndAudioLanguage(shareId, language)
    End Function

End Class
